<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Index extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('url','weibooauth','html'));
		$this->load->model('usermanager');
	}
	
	/**
	 * 
	 * 网站的首页
	 */
	public function index()
	{
		if($this->weixiao->is_login())
		{
			$data = array(
				'user' => $this->weixiao->get_cur_user(),
			);
			//获得所有绑定的数据
			$bindings = $this->usermanager->get_binding_by_uid($this->weixiao->get_cur_user()->id);
			foreach ($bindings as $binding)
			{
				switch ($binding->sns_website)
				{
					case UserManager::sns_website_sina:
						$data['binding_sina'] = $binding;
						//读sina的数据
						$c = new WeiboClient( WB_AKEY , WB_SKEY , $binding->sns_oauth_token , $binding->sns_oauth_token_secret);
						$me = $c->verify_credentials();
						$data['sina'] = $me;
						$friends = $c->friends_ids(null , 5000 , $binding->sns_uid);
						$data['friends_sina'] = $friends['ids'];
						break;
				}
			}
			$this->load->view('index_login', $data);
		}
		else
		{
			$this->load->view('index_not_login');
		}
	}
	
	public function logout() {
		$this->weixiao->logout();
		redirect('/');
	}
}
?>